#include "../../ecv/structs.h"
#include "../../ecv/treeutils.h"

int main (void)
{
  ecv_tree * t1 = ecv_tree_createtree();
  ecv_tree * t2 = ecv_tree_createtree();
  ecv_node * l11 = ecv_list_createnodefull(0,0,1);
  ecv_node * l12 = ecv_list_createnodefull(1,2,1);
  ecv_node * l13 = ecv_list_createnodefull(0,3,1);
  ecv_node * l14 = ecv_list_createnodefull(0,4,1);
  ecv_node * l21 = ecv_list_createnodefull(0,5,2);
  ecv_node * l22 = ecv_list_createnodefull(0,6,2);
  ecv_node * l23 = ecv_list_createnodefull(0,7,2);

  ecv_list_merge(l11,l12);
  ecv_list_merge(l12,l13);
  ecv_list_merge(l11,l14);

  ecv_list_merge(l21,l22);
  ecv_list_merge(l21,l23);

  t1->root = l11;
  t2->root = l21;
  ecv_tree_addtree(t1,t2);

  ecv_tree * t = t1;

  printf ("traversing before renumbering\n");

  while (t != NULL)
    {
      printf ("t->root->id %i, t->root->i %i, t->root->j %i\n", t->root->id, t->root->i, t->root->j);
      t = t->child;
    }

  ecv_list_merge(l12,l22);

  ecv_node * n = ecv_list_findhead(l22);
  int lowestid=n->id;

  while (n!=NULL)
    {
      if (lowestid > n->id)
	lowestid = n->id;
      n=n->child;
    }

  n = ecv_list_findhead(l22);

  while (n!=NULL)
    {
      n->id = lowestid;
      n=n->child;
    }

  t = t1;
  printf ("traversing after renumbering\n");
  while (t != NULL)
    {
      printf ("t->root->id %i, t->root->i %i, t->root->j %i\n", t->root->id, t->root->i, t->root->j);
      t = t->child;
    }

  return 0;
}
